package com.itheima.service.Impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.MemberDao;
import com.itheima.dao.OrderDao;
import com.itheima.dao.ReportDao;
import com.itheima.dao.SetMealDao;
import com.itheima.service.ReportService;
import com.itheima.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 吴
 * @version V1.0
 * @Description
 * @Package com.itheima.service.Impl
 * @date 2021/11/30 15:26
 */
@Service(interfaceClass = ReportService.class)
@Transactional
public class ReportServiceImpl implements ReportService {

    @Autowired
    private MemberDao memberDao;

    @Autowired
    private OrderDao orderDao;

    @Autowired
    private SetMealDao setMealDao;

    @Autowired
    private ReportDao reportDao;

    /**
     * 查询运营情况
     * （当前日期）
     * （今日新增会员数、总会员数、本周新增会员数、本月新增会员数）
     * （今日预约数、今日到诊数、本周预约数、 本周到诊数、本月预约数、本月到诊数）
     * （ 热门套餐）
     * @return
     */
    @Override
    public Map<String, Object> findBusinessData() throws Exception {

        //获得当前日期
        String today = DateUtils.parseDate2String(DateUtils.getToday());
        //获得本周一的日期
        String thisWeekMonday = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
        //获得本月第一天的日期
        String firstDayThisMonth = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());

        // 今日新增会员数
        int todayNewMember = memberDao.selectMemberCountTodayByRegTime(today);
        // 本周新增会员数
        int thisWeekNewMember = memberDao.selectMemberCountAfterDateByRegtime(thisWeekMonday);
        // 本月新增会员数
        int thisMonthNewMember  = memberDao.selectMemberCountAfterDateByRegtime(firstDayThisMonth);
        // 总会员数
        int totalMember = memberDao.selectMemberCount();
        // 今日预约数
        int todayOrderNumber = orderDao.selectTodayOrderByOrderDate(today);
        // 今日到诊数
        int todayVisitsNumber = orderDao.selectOrderVisitsCountByOrderDate(today);
        // 本周预约数
        int thisWeekOrderNumber = orderDao.selectAfterOrderCountByOrderDate(thisWeekMonday);
        // 本周到诊数
        int thisWeekVisitsNumber = orderDao.selectAfterOrderVisitsCountByOrderDate(thisWeekMonday);
        // 本月预约数
        int thisMonthOrderNumber = orderDao.selectAfterOrderCountByOrderDate(firstDayThisMonth);
        // 本月到诊数
        int thisMonthVisitsNumber  = orderDao.selectAfterOrderVisitsCountByOrderDate(firstDayThisMonth);
        // 热门套餐(前三)
        List<Map<String,Object>> hotSetmeal = setMealDao.selectHotSetmeal();

        Map<String,Object> map = new HashMap<>();

        map.put("reportDate",today);
        map.put("todayNewMember",todayNewMember);
        map.put("thisWeekNewMember",thisWeekNewMember);
        map.put("thisMonthNewMember",thisMonthNewMember);
        map.put("totalMember",totalMember);
        map.put("todayOrderNumber",todayOrderNumber);
        map.put("todayVisitsNumber",todayVisitsNumber);
        map.put("thisWeekOrderNumber",thisWeekOrderNumber);
        map.put("thisWeekVisitsNumber",thisWeekVisitsNumber);
        map.put("thisMonthOrderNumber",thisMonthOrderNumber);
        map.put("thisMonthVisitsNumber",thisMonthVisitsNumber);
        map.put("hotSetmeal",hotSetmeal);

        return map;
    }


}
